package com.studyprojectbacked.mapper;

import com.studyprojectbacked.entity.Account;
import com.studyprojectbacked.entity.dto.AccountUser;
import com.studyprojectbacked.entity.dto.RegisterAccount;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

  @Select("select * from db_account where username = #{text} or email = #{text}")
  Account findAccountByNameOrEmail(String text);

  @Select("select * from db_account where username = #{text} or email = #{text}")
  AccountUser findAccountUserByNameOrEmail(String text);

  @Insert("insert into db_account (username, password, email) " +
          "values (#{ra.username}, #{ra.password}, #{ra.email})")
  int createAccount(@Param("ra")RegisterAccount ra);

  @Update("update db_account set password = #{password} where email = #{email}")
  int resetPasswordByEmail(@Param("password") String password, @Param("email") String email);

}
